package com.besovideo.mpu;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.smarteye.mpu.MPUGlobal;
import com.smarteye.mpu.MainService.Connection;
import com.smarteye.mpu.coresdk.MPUDefine;
import com.smarteye.mpu.coresdk.MPUKey;

public class TransmissionTypeDialog extends Dialog {

	Context context;
	int lay;
	private Connection mConnection;

	CheckBox m_CheckBoxTransactionTypeVideo;
	CheckBox m_CheckBoxTransactionTypePhoto;
	CheckBox m_CheckBoxTransactionTypeTalkBack;

	public TransmissionTypeDialog(Context context) {
		super(context, R.style.TransparentDialogHaveTitle);
		this.context = context;
		this.lay = R.layout.transmission_type;
		mConnection = ((MPUGlobal) ((MainActivity) context).getApplication())
				.getConnection();
	}

	@Override
	protected void onStop() {
		super.onStop();
		int type = 0;
		if (m_CheckBoxTransactionTypeTalkBack.isChecked()) {
			type |= MPUDefine.BVCU_MEDIADIR_TALKONLY;
		}
		if (m_CheckBoxTransactionTypeVideo.isChecked()) {
			type |= MPUDefine.BVCU_MEDIADIR_VIDEOSEND;
		}
		mConnection.setSDKOptionInt(MPUKey.MPU_I_USER_MEDIADIR, type);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(lay);
		m_CheckBoxTransactionTypeVideo = (CheckBox) findViewById(R.id.checkBoxTransactionTypeVideo);
		m_CheckBoxTransactionTypeTalkBack = (CheckBox) findViewById(R.id.checkBoxTransactionTypeTalkBack);

		int type = mConnection.getSDKOptionInt(MPUKey.MPU_I_USER_MEDIADIR);
		if ((type & MPUDefine.BVCU_MEDIADIR_TALKONLY) == MPUDefine.BVCU_MEDIADIR_TALKONLY)
			m_CheckBoxTransactionTypeTalkBack.setChecked(true);
		if ((type & MPUDefine.BVCU_MEDIADIR_VIDEOSEND) == MPUDefine.BVCU_MEDIADIR_VIDEOSEND)
			m_CheckBoxTransactionTypeVideo.setChecked(true);

		m_CheckBoxTransactionTypeVideo
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {
					@Override
					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						// TODO Auto-generated method stub

					}
				});

		m_CheckBoxTransactionTypePhoto = (CheckBox) findViewById(R.id.checkBoxTransactionTypePhoto);
		m_CheckBoxTransactionTypePhoto
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {
					@Override
					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						// TODO Auto-generated method stub

					}
				});

		m_CheckBoxTransactionTypeTalkBack
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {
					@Override
					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						// TODO Auto-generated method stub

					}
				});
	}
}